Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.pvzChannelVivo = undefined;
var $2pvzChannelWeb = require("pvzChannelWeb");
var $2kc = require("kc");
exports.pvzChannelVivo = /* */function (_n$pvzChannelWeb5) {
  babel_inherits(_class11, _n$pvzChannelWeb5);
  var _super114 = babel_createSuper(_class11);
  function _class11() {
    var _this273;
    babel_classCallCheck(this, _class11);
    _this273 = _super114.apply(this, arguments);
    _this273.channel = "vivo";
    _this273.paraMap = new Map([["bannerAd", "54422a6ac8644291a9f29f6620655007"], ["nativeBannerAd", "03154b46e03b49cb9d496d207264e7f1"], ["insertAd", "807f7131e4294e40a3d62092a9c4eadb"], ["nativeInsertAd", "e05c20e7f3e74257b51552e2b33b9c79"], ["vedioAd", "f13d08f1d1764a4d9f8c6b72b8a33dbe"], ["gird9", "fbe490cba3e5444a962fc37e773562e4"], ["ctrlId", "63c652bdf9d13c5453ecea23"], ["gid", "63d8b2fbf9d13c5453eef4bb"]]);
    _this273.channelObj = window.qg;
    _this273.bannerTimeId = -1;
    _this273.lastCustomShowTime = 0;
    _this273.customGapSec = 5e3;
    return _this273;
  }
  babel_createClass(_class11, [{
    key: "getSysInfo",
    value: function getSysInfo() {
      this.sysInfo || (this.sysInfo = this.channelObj.getSystemInfoSync());
      return this.sysInfo;
    }
  }, {
    key: "exit",
    value: function exit() {
      this.channelObj.exitApplication();
    }
  }, {
    key: "init",
    value: function init() {
      var _this274 = this;
      babel_get(babel_getPrototypeOf(_class11.prototype), "init", this).call(this);
      var e = {
        id: this.getPara("ctrlId")
      };
      $2kc.default.jpost("https://ga.gametdd.com/adCtrl/agd/conf", e, function (e, t) {
        if (e) {
          $2kc.default.err(e);
        } else if ("" + t.code == "0") {
          _this274.ctrl = t.data;
          $2kc.default.log("返回", _this274.ctrl);
        } else {
          $2kc.default.err("返回值错误:" + JSON.stringify(t));
        }
      });
    }
  }, {
    key: "hasPrivacy",
    value: function hasPrivacy() {
      return true;
    }
  }, {
    key: "showVideo",
    value: function showVideo(e) {
      var _this275 = this;
      var t = this.getPara("vedioAd");
      if (t) {
        $2kc.default.log("showVideo", t);
        this.rewardedVideoAd = this.channelObj.createRewardedVideoAd({
          posId: t
        });
        this.rewardedVideoAd.offLoad();
        this.rewardedVideoAd.offError();
        this.rewardedVideoAd.offClose();
        this.videoFns.onLoad = function () {
          $2kc.default.log("激励视频 广告加载成功");
          _this275.rewardedVideoAd.show().then(function () {
            $2kc.default.log("激励视频 广告显示");
          }).catch(function (e) {
            $2kc.default.err(e);
            _this275.rewardedVideoAd.load().then(function () {
              $2kc.default.log("手动加载成功");
            });
          });
        };
        this.videoFns.onError = function (t) {
          $2kc.default.err(t);
          e.failCall();
          _this275.channelObj.showToast({
            message: "暂无广告"
          });
        };
        this.videoFns.onClose = function (t) {
          $2kc.default.log("激励视频 广告关闭", t);
          t && t.isEnded && e.sucCall();
          e.endCall();
        };
        this.rewardedVideoAd.onLoad(this.videoFns.onLoad);
        this.rewardedVideoAd.onError(this.videoFns.onError);
        this.rewardedVideoAd.onClose(this.videoFns.onClose);
      }
    }
  }, {
    key: "showGird9",
    value: function showGird9() {
      var e = this.getPara("gird9");
      if (!e) {
        return;
      }
      var t = this.channelObj;
      if (t.createBoxPortalAd) {
        this.boxPortalAd = t.createBoxPortalAd({
          posId: e,
          marginTop: 200
        });
        this.boxPortalAd.onError(function (e) {
          $2kc.default.log("盒子九宫格广告加载失败", e);
        });
        this.boxPortalAd.onClose(function () {
          $2kc.default.log("close九宫格");
          this.boxPortalAd.isDestroyed || this.boxPortalAd.show();
        });
        this.boxPortalAd.show().then(function () {
          $2kc.default.log("九宫格show success");
        });
      } else {
        $2kc.default.log("暂不支持互推盒子相关 API");
      }
    }
  }, {
    key: "closeGird9",
    value: function closeGird9() {
      if (null != this.boxPortalAd) {
        this.boxPortalAd.isDestroyed = true;
        this.boxPortalAd.destroy();
      }
    }
  }, {
    key: "showBanner",
    value: function showBanner(e, t, a) {
      var n = this.getPara("bannerAd");
      if (n) {
        this.bannerAd = this.channelObj.createBannerAd({
          posId: n,
          adIntervals: 30
        });
        this.bannerAd.onError(function (e) {
          $2kc.default.log("banner广告加载失败" + JSON.stringify(e));
        });
        this.bannerAd.show().then(function () {
          $2kc.default.log("banner广告展示完成");
        }).catch(function (e) {
          $2kc.default.log("banner广告展示失败" + JSON.stringify(e));
        });
      }
    }
  }, {
    key: "closeBanner",
    value: function closeBanner() {
      this.bannerAd && this.bannerAd.hide();
    }
  }, {
    key: "showBannerByTime",
    value: function showBannerByTime() {
      var _this276 = this;
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
      var t = 30;
      var a = this.getCtrl("p5");
      a && (t = a);
      this.bannerTimeId >= 0 && clearInterval(this.bannerTimeId);
      this.closeBanner();
      t < 30 && (t = 30);
      this.showBanner(e, null, "battle");
      this.bannerTimeId = setInterval(function () {
        _this276.showBanner(e, null, "battle");
      }, 1e3 * t);
    }
  }, {
    key: "closeBannerByTime",
    value: function closeBannerByTime() {
      this.bannerTimeId >= 0 && clearInterval(this.bannerTimeId);
      this.closeBanner();
    }
  }, {
    key: "showCustomAd",
    value: function showCustomAd(e, t, a) {
      var _this277 = this;
      var n = e ? "customAd1" : "customAd2";
      if (Date.now() - this.lastCustomShowTime < this.customGapSec) {
        return void $2kc.default.log("custom广告间隔未到", this.customGapSec);
      }
      this.lastCustomShowTime = Date.now();
      if (e) {
        if (!t || !this.ctrl || !this.ctrl.p4 || "0" == this.ctrl.p4) {
          return;
        }
      } else if (!(t || this.ctrl && this.ctrl.p1 && "0" != this.ctrl.p1)) {
        return void $2kc.default.log("showCustomAd不执行", t, this.ctrl.p1);
      }
      var s = this.ctrl && this.ctrl.p2 ? parseInt(this.ctrl.p2) : 0;
      setTimeout(function () {
        var t = _this277.channelObj;
        var s = e ? _this277.getPara("nativeBannerAd") : _this277.getPara("nativeInsertAd");
        var o = _this277.getSysInfo().windowHeight;
        $2kc.default.log("showCustomAd", n, s, "windowHeight", o);
        var l = {
          posId: s,
          style: {
            top: o / 2 - 500
          }
        };
        a && (l.style = a);
        _this277[n] = t.createCustomAd(l);
        _this277[n].offError();
        _this277[n].onError(function (t) {
          $2kc.default.log("原生模板广告加载失败" + JSON.stringify(t));
          if (e) {
            _this277.showBanner();
          } else {
            _this277.showInter();
          }
        });
        _this277[n].show().then(function () {
          $2kc.default.log("原生模板广告展示完成");
        }).catch(function (e) {
          $2kc.default.log("原生模板广告展示失败" + JSON.stringify(e));
        });
      }, 1e3 * s);
    }
  }, {
    key: "closeCustomAd",
    value: function closeCustomAd(e) {
      var t = e ? "customAd1" : "customAd2";
      this[t] && this[t].hide();
    }
  }]);
  return _class11;
}($2pvzChannelWeb.pvzChannelWeb);